package classes.pack;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class TestTimer extends Service
{
	private static final long UPDATE_INTERVAL = 6000;
	Context context = this;
	private Timer timer = new Timer();


	public void onCreate()
	{
		Log.i("T-TIMER", "CREATED");
		runTheLoop();
	}

	protected void runTheLoop() 
	{

	    timer.scheduleAtFixedRate(new TimerTask()
	    {
	        @Override
	        public void run() 
	        {
	
	        	Log.i("TEST", "update!!!");
			    Toast.makeText(context, "CALL", Toast.LENGTH_LONG).show();
			}
	    }, 0, UPDATE_INTERVAL);
	
	}
	
	@Override   
	public int onStartCommand(Intent intent, int flags, int startId) 
	{
		Toast.makeText(this, "Starte Service", Toast.LENGTH_SHORT).show();

		return super.onStartCommand(intent,flags,startId);
	}

	public void onDestroy() 
	{
	    super.onDestroy();

	    Toast.makeText(this, "Stoppe Service", Toast.LENGTH_LONG).show();

	}

	// We return the binder class upon a call of bindService

	

	public class MyBinder extends Binder 
	{
	    TestTimer getService() 
	    {
		        return TestTimer.this;
		}
	}

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

}
